<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Roles
 *
 * This model represents roles. It operates the following two tables
 *
 * @package    Tank_auth
 * @author    theshiftexchange
 */
class Roles extends CI_Model
{
        function __construct()
    {
        parent::__construct();
    }

    /**
     * Get all user roles and return them as a string with a '%' seperating them
     *
     * @param    int
     * @return    string
     */
    function get_user_roles($user_id)
    {
            
            $query = $this->db->query("SELECT * 
                                       FROM users_roles
                                       INNER JOIN roles ON users_roles.rolesID=roles.rolesID
                                       WHERE userID = ".$user_id);

            $roles = null;

            foreach ($query->result() as $row)
            {
                $roles = ($roles.$row->name);
            }

            return $roles;
    }
    function set_roles($user_id,$role_id)
    {
        $this->db->insert('users_roles',array('userID'=>$user_id,'rolesID'=>$role_id));
        return $this->db->affected_rows();
    }
    function update_user_roles($user_id,$role_id){
        $this->db->where('userID',$user_id);
        $this->db->update('users_roles',array('rolesID'=>$role_id));
        return $this->db->affected_rows();
    }
    function get_roles()
    {
        $query = $this->db->get('roles');
        return $query->result();
    }
    
}

/* End of file roles.php */
/* Location: ./application/models/auth/roles.php */  